home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gnu / adainc / a-nuflra.adb < prev    next >
Text File  |  1996-01-30  |  4KB  |  105 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                         GNAT RUNTIME COMPONENTS                          --
  4. --                                                                          --
  5. --            A D A . N U M E R I C S . F L O A T _ R A N D O M             --
  6. --                                                                          --
  7. --                                 B o d y                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.10 $                             --
  10. --                                                                          --
  11. --           Copyright (c) 1992,1993,1994 NYU, All Rights Reserved          --
  12. --                                                                          --
  13. -- The GNAT library is free software; you can redistribute it and/or modify --
  14. -- it under terms of the GNU Library General Public License as published by --
  15. -- the Free Software  Foundation; either version 2, or (at your option) any --
  16. -- later version.  The GNAT library is distributed in the hope that it will --
  17. -- be useful, but WITHOUT ANY WARRANTY;  without even  the implied warranty --
  18. -- of MERCHANTABILITY  or  FITNESS FOR  A PARTICULAR PURPOSE.  See the  GNU --
  19. -- Library  General  Public  License for  more  details.  You  should  have --
  20. -- received  a copy of the GNU  Library  General Public License  along with --
  21. -- the GNAT library;  see the file  COPYING.LIB.  If not, write to the Free --
  22. -- Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.        --
  23. --                                                                          --
  24. ------------------------------------------------------------------------------
  25.  
  26. --  This implementation is derived from LSN 1055 written by Ken Dritz.
  27.  
  28. with Ada.Calendar;
  29. with Unchecked_Deallocation;
  30.  
  31. package body Ada.Numerics.Float_Random is
  32.  
  33.    --------------
  34.    -- Finalize --
  35.    --------------
  36.  
  37.    procedure Finalize (Gen : in out Generator) is
  38.  
  39.       procedure Destroy_State is
  40.         new Unchecked_Deallocation (ANR.State, Access_State);
  41.  
  42.    begin
  43.       Destroy_State (Gen.State);
  44.    end Finalize;
  45.  
  46.    -----------
  47.    -- Image --
  48.    -----------
  49.  
  50.    function Image (Of_State : State) return String is
  51.    begin
  52.       return ANR.Image (ANR.State (Of_State));
  53.    end Image;
  54.  
  55.    ------------
  56.    -- Random --
  57.    ------------
  58.  
  59.    function Random (Gen : Generator) return Uniformly_Distributed is
  60.       U : Float;
  61.  
  62.    begin
  63.       ANR.Random (Gen.State.all, U);
  64.       return U;
  65.    end Random;
  66.  
  67.    -----------
  68.    -- Reset --
  69.    -----------
  70.  
  71.    procedure Reset (Gen : in Generator; Initiator : in Integer) is
  72.    begin
  73.       ANR.Reset (Gen.State.all, Initiator);
  74.    end Reset;
  75.  
  76.    procedure Reset (Gen : in Generator) is
  77.    begin
  78.       ANR.Reset (Gen.State.all);
  79.    end Reset;
  80.  
  81.    procedure Reset (Gen : in Generator; From_State : in State) is
  82.    begin
  83.       Gen.State.all := ANR.State (From_State);
  84.    end Reset;
  85.  
  86.    ----------
  87.    -- Save --
  88.    ----------
  89.  
  90.    procedure Save (Gen : in Generator; To_State : out State) is
  91.    begin
  92.       To_State := State (Gen.State.all);
  93.    end Save;
  94.  
  95.    -----------
  96.    -- Value --
  97.    -----------
  98.  
  99.    function Value (Coded_State : String) return State is
  100.    begin
  101.       return State (ANR.Value (Coded_State));
  102.    end Value;
  103.  
  104. end Ada.Numerics.Float_Random;
  105.